<?php
namespace plugin\banmichaoqiangbizhi\admin;
use app\admin\common\Baseadmin;
use think\facade\Db; 
use plugin\banmichaoqiangbizhi\common\Common;
use plugin\banmichaoqiangbizhi\validate\SettingsValidate as validates ;
class Settings extends Baseadmin
{
    
    
      protected $output_set = ['search_placeholder','index_background_img','article_examine','reply_examine','tx_map_key'];
      
      protected $output_json= ['plugin_tabbar','my_list1','my_list2'];
      
      
    /**
     * 查询json
     * @param index
     * @param    json类型的字段 $output_json
     */
      public function index() {
   
          //获取应用基本配置
          $config =   plugin_config();
 
        
          $data['set_find']=$config; 
          ajaxmsg('ok', 200,$data);     
      }
    /**
     * 保存json
     * @param save_tabbar
     * @param  json类型的字段 $output_json
     */
      public function save_tabbar() {
           $request= (new validates())->IsCheck();
 
           //先获取原始配置文件 在保存
           $config =   plugin_config();
       
           $config['plugin_tabbar']  =  json_decode($request['plugin_tabbar'],true);
           
           $set_find=json_encode($config);
   
           Db::name('home_plugin_list_config')->where('catalogue','banmichaoqiangbizhi')->update(['config' => $set_find ]);
       
         
          ajaxmsg('保存成功', 200);  
      }
      
      //初始化tabbar
      public function initialization_tabbar() {
          
          $config =    plugin_config_initialization();
          
        
          $data['set_find']=$config; 
          ajaxmsg('初始化成功', 200,$data);     
          
      }
      
      
      
          /**
     * 保存json
     * @param save_tabbar
     * @param  json类型的字段 $output_json
     */
      public function save_my_list() {
           $request= (new validates())->IsCheck();
 
           //先获取原始配置文件 在保存
           $config =   plugin_config();
       
           $config['my_list1']  =  json_decode($request['my_list1'],true);
           $config['my_list2']  =  json_decode($request['my_list2'],true);
           
           $set_find=json_encode($config);
   
           Db::name('home_plugin_list_config')->where('catalogue','banmichaoqiangbizhi')->update(['config' => $set_find ]);
       
         
          ajaxmsg('保存成功', 200);  
      }
    /**
     * 获取基本设置信息
     * @param set_find
     * @param  output_set 字段 
     */
      public function set_find() {
          $output=$this->output_set;
          $set_find  = (new Common())->settings($output); 
          $data['set_find']=$set_find; 
          ajaxmsg('ok', 200,$data);     
      }
    /**
     * 保存基本设置
     * @param save_tabbar
     * @param  output_set 字段 
     */
      public function set_save() {
          $request= (new validates())->IsCheck();
          $output=$this->output_set;
          $set_find  = (new Common())->settings_save($output,$request); 
          ajaxmsg('保存成功', 200);  
      }
    
    
}